﻿using DayuCode.Designer.Entity;
using DayuCode.Designer.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DayuCode.Designer.Service
{
    public class CodeFragmentHandler
    {
        private static string getBaseUrl(string methodName)
        {
            return AppInstance.ApiServer + "api/base/dayucode_codeFragmentHandler/" + methodName;
        }

		public static List<CodeFragment> getAllCodeFragments()
		{
			List<CodeFragment> obj = QHttpClient.Post<List<CodeFragment>>(getBaseUrl("getAllCodeFragments"), new { });
			return obj;
		}

		public static CodeFragment getCodeFragment(long id)
		{
			CodeFragment obj = QHttpClient.Post<CodeFragment>(getBaseUrl("getCodeFragment"), new { id = id });
			return obj;
		}

		public static void updateCodeTemplateText(long id, string codeTemplateText)
		{
			QHttpClient.Execute(getBaseUrl("updateCodeTemplateText"), new { id = id, codeTemplateText= codeTemplateText });
		}

		public static void deleteCodeFragment(long id)
		{
			QHttpClient.Execute(getBaseUrl("deleteCodeFragment"), new { id = id });
		}

		public static CodeFragment saveCodeFragment(CodeFragment item)
		{
			CodeFragment obj = QHttpClient.Post<CodeFragment>(getBaseUrl("saveCodeFragment"), new { item = item });
			return obj;
		}
	}
}
